import GameUI from "./GameUI";
import LevelConfig from "./LevelConfig";

const { ccclass, property } = cc._decorator;

@ccclass
export default class ItemBoard extends cc.Component {

    private isFirst: boolean = true;

    private onBeginContact(contact, selfCollider, otherCollider) {
        // console.log("碰撞", selfCollider.node.name, otherCollider.node.name);
        // console.log("碰撞1111111111", selfCollider.node.group, otherCollider.node.group);
        if (selfCollider.node.group != otherCollider.node.group && otherCollider.node.group == "check") {
            if (this.isFirst && selfCollider.node.parent.childrenCount == 1) {
                // selfCollider.node.parent.destroy();
                this.isFirst = false;
                // 创建新层
                GameUI.instance.changeColorToNormal();
                if (GameUI.instance.gameData.layerCur < GameUI.instance.gameData.layerMax) {
                    const name = LevelConfig.instance.getLayerName();
                    const info = { id: 1, path: name, pos: cc.v2(0, 0)/*cc.v2(Tools.random(-100, 100), Tools.random(-100, 100))*/, boards: [], isGray: true };
                    GameUI.instance.createLayer(info);
                }
            }
            selfCollider.node.destroy();
        }
    }

    // /**检测当前螺丝数量，根据螺丝数目决定是否亮起新的板块 */
    // private getBoardNum() {
    //     let layer = this.node.parent;
    //     let layers = layer.parent.children;
    //     let num = 0;
    //     for (let i = 0; i < layers.length; i++) {
    //         let boards = layers[i].children;
    //         for (let j = 0; j < boards.length; j++) {
    //             num += boards[j].childrenCount;
    //         }
    //     }
    //     return num;
    // }
}